Method chaining to split logic into a chain-look to make more understandable pieces of code

class MyCar {
	function setPedals() {
	// code logic
	return this;
	}
 
	function setWheels() {
	// code logic
	return this;
	}
 
	function setEngine() {
	// code logic
	}
}
 
$myCar = new MyCar();
$myCar.setPedals().setWheels().setEngine();

This pattern also called Fluent Interface. More information can be found here:
Method chaining
Fluent interface

Leave a Reply